/**
 *@Author Rain_tdk
 *@Date:  2018/11/23
 *@Description:
 *@ReviseAutor:
 *@ReviseDate:
 */

'use strict'
import axios from 'axios'
import { Message } from 'element-ui'

// create an axios instance
const service = axios.create({
  baseURL: '/mock', // api 的 base_url
  timeout: 5000 // request timeout
})

// request interceptor
service.interceptors.request.use(
  config => {
    return config
  },
  error => {
    console.log(error) // for debug
    Promise.reject(error)
  }
)
// response interceptor
service.interceptors.response.use(
  response => {
    let rpd =response['data'];
    const state = rpd.state;
    if(state===200){
      Message({
        message: rpd.message || '操作成功',
        type: 'success',
      })
    }
    return rpd;
  },
  error => {
    console.log('err' + error) // for debug
    Message({
      message: error.message,
      type: 'error',
      duration: 5 * 1000
    })
    return Promise.reject(error)
  }
)

export default service
